cmake_minimum_required(VERSION 3.5 FATAL_ERROR)

project(recipe-01 LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

find_package(PythonInterp REQUIRED)                                                                 # 寻找python解释器
find_program(BASH_EXECUTABLE NAMES bash REQUIRED)                                                   # 寻找bash程序

add_library(sum_integers sum_integers.cpp)

add_executable(main main.cpp)
target_link_libraries(main sum_integers)

add_executable(cpp_test test.cpp)                                                                   # c++程序需要编译后测试，python/bash可以动态测试
target_link_libraries(cpp_test sum_integers)

enable_testing()                                                                                    # 开始测试，测试该目录的所有测试项目

add_test(NAME cpp_test
        COMMAND $<TARGET_FILE:cpp_test>)                                                            # cpp_test是一个测试程序，里面有测试案例

add_test(NAME bash_test
        COMMAND ${BASH_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test.sh $<TARGET_FILE:main>)         # bash test.sh main bash.sh只是一个判断相等的功能 由main计算

add_test(NAME python_test_long
        COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test.py --executable $<TARGET_FILE:main>)      # /usr/bin/python3.6 test.py --executable main
add_test(NAME python_test_long2
        COMMAND ${PYTHON_EXECUTABLE} test.py --executable $<TARGET_FILE:main>
        WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})                                                          # 和上面等价

add_test(NAME python_test_short
        COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test.py --short --executable $<TARGET_FILE:main>)      # /usr/bin/python3.6 test.py --executable main
